//
//  NewTaskTableViewCell.m
//  BaishidaiKnight
//
//  Created by mac book on 2019/1/28.
//  Copyright © 2019年 sy. All rights reserved.
//

#import "NewTaskTableViewCell.h"

@interface NewTaskTableViewCell ()
@property(nonatomic,strong) UIButton * iconBtn;
@property(nonatomic,strong) UILabel * contentLabel;
@property(nonatomic,strong) UILabel * distanceLabel;
@property(nonatomic,strong) UIView * lineView;
@end

@implementation NewTaskTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self createSubviews];
    }
    return self;
}

#pragma mark - createSubviews
-(void)createSubviews{
    
    [self.contentView addSubview:self.iconBtn];
    [self.contentView addSubview:self.distanceLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.contentView);
        make.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(1);
        
    }];
    
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(10);
        make.size.mas_equalTo(CGSizeMake(25, 25));

    }];
    
    [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-10);
        make.width.mas_equalTo(self.contentView).multipliedBy(0.25);

    }];
    

    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self.contentView);
        make.right.equalTo(self.distanceLabel.mas_left);
        make.left.equalTo(self.iconBtn.mas_right).offset(10);

    }];
    
    
}


#pragma mark - setter

- (void)setTaskModel:(TaskModel *)taskModel withType:(NSInteger)type{
    
    
    TaskModel *itemModel = taskModel.items.firstObject;
    NSString *strMoney;
    if (type == 1) {
         strMoney  = [NSString stringWithFormat:@"%@ \n%@",itemModel.site_name,itemModel.shopaddress];
    }else{
        strMoney  = [NSString stringWithFormat:@"%@ \n%@",itemModel.site_name,itemModel.site_addr];

    }
  
    NSMutableAttributedString* attributeStr  = [[NSMutableAttributedString alloc]initWithString:strMoney];
    [attributeStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.f],NSForegroundColorAttributeName:[UIColor colorWithRed:0/255.f green:0/255.f blue:0/55.f alpha:1.0]} range:[strMoney rangeOfString:itemModel.site_name]];
    _contentLabel.attributedText = attributeStr;
    
    NSString *stra = [CommonUntils getTheCorrectNum:itemModel.location];
    strMoney = [NSString stringWithFormat:@"%@km取货",stra];
    attributeStr  = [[NSMutableAttributedString alloc]initWithString:strMoney];
    [attributeStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.f],NSForegroundColorAttributeName:[UIColor colorWithRed:248/255.f green:159/255.f blue:39/255.f alpha:1.0]} range:[strMoney rangeOfString:[NSString stringWithFormat:@"%@km",stra]]];
    _distanceLabel.attributedText = attributeStr;
    self.iconBtn.selected = YES;
    self.distanceLabel.hidden = NO;
}




#pragma mark - 懒加载
-(UIButton *)iconBtn{
    if(!_iconBtn){
        _iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_iconBtn setImage:[UIImage imageNamed:@"icon_sendstatus_default"] forState:UIControlStateNormal];
        [_iconBtn setImage:[UIImage imageNamed:@"icon_sendstatus_enter"] forState:UIControlStateSelected];
    }
    return _iconBtn;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.font = [UIFont systemFontOfSize:14.f];
        _contentLabel.numberOfLines = 0;
        _contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _contentLabel.textColor =  kMyColor(113, 113, 113);
        
    }
    return _contentLabel;
}

-(UILabel *)distanceLabel{
    if(!_distanceLabel){
        _distanceLabel = [[UILabel alloc]init];
        _distanceLabel.font = [UIFont systemFontOfSize:12.f];
        _distanceLabel.textColor =  kMyColor(113, 113, 113);
        _distanceLabel.textAlignment = NSTextAlignmentRight;
    }
    return _distanceLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor =  kMyColor(231, 231, 231);
    }
    return _lineView;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
